/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package modele;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Collection;
import java.util.TreeSet;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author wkhim
 */
public class DAO {

    public static Collection<Dep> getLesDeps() {
        Collection<Dep> d = new TreeSet<Dep>();
        try {
            Connection con = Connect.get();
            Statement req;
            req = con.createStatement();
            ResultSet rs = req.executeQuery("select distinct departement from medecin");
            while (rs.next()) {
                d.add(new Dep(rs.getString("departement")));
            }
            rs.close();
        } catch (SQLException ex) {
            Logger.getLogger(DAO.class.getName()).log(Level.SEVERE, null, ex);
        }
        return d;
    }

    public static Collection<Spe> getLesSpes() {
        Collection<Spe> s = new TreeSet<Spe>();
        try {
            Connection con = Connect.get();
            Statement reqS;
            reqS = con.createStatement();
            ResultSet rsS = reqS.executeQuery("select distinct specialitecomplementaire as spe from medecin where specialitecomplementaire is not null");
            while (rsS.next()) {
                s.add(new Spe(rsS.getString("spe")));
            }
            rsS.close();
        } catch (SQLException ex) {
            Logger.getLogger(DAO.class.getName()).log(Level.SEVERE, null, ex);
        }
        return s;
    }

    public static Collection<Med> getLesMeds() {
        Collection<Med> m = new TreeSet<Med>();
        try {
            Connection con = Connect.get();
            Statement reqM;
            reqM = con.createStatement();
            ResultSet rsM = reqM.executeQuery("select * from medecin");
            while (rsM.next()) {
                m.add(new Med(rsM.getString("nom"), rsM.getString("prenom"), rsM.getString("adresse"), rsM.getString("tel"), rsM.getString("specialitecomplementaire"), rsM.getString("departement"), rsM.getString("id")));
            }
            rsM.close();
        } catch (SQLException ex) {
            Logger.getLogger(DAO.class.getName()).log(Level.SEVERE, null, ex);
        }
        return m;
    }
}
